<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>现金应收应付</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <link rel="stylesheet" href="layui/css/layui.css"/>
    <script type="text/javascript" src="layui/layui.js"></script>
    <script type="text/javascript" src="layui/tableSelect.js"></script>
</head>
<body>
<!--表格上方的 工具条-->
<script type="text/html" id="fundToolBar">
    <button class="layui-btn layui-btn-sm" lay-event="insert"><i
            class="layui-icon">&#xe654;</i>新增</button>
    <button class="layui-btn layui-btn-sm" lay-event="deleteAll">批量删除</button>

    <div style="width:800px;float:right;height:30px;">
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="width: 110px;text-align: center">时间 </label>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <input  class="layui-input" autocomplete="off" placeholder="请输入时间" name="timeQ" id="timeQ">
        </div>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="width: 110px;text-align: center">基金类型</label>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <select  name="businessType" id="businessTypeID">
                <option value="0" placeholder="请选择">请选择</option>
                <option value="1">管理费</option>
                <option value="2">托管费</option>
                <option value="3">存款利息</option>
                <option value="4">申购赎回</option>
            </select>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <button  class="layui-btn layui-btn-primary" lay-submit="" lay-event="search"><i class="layui-icon">&#xe615;</i>搜索
            </button>
        </div>
    </div>

    <!--表格最后一列的操作按钮的工具栏-->
    <div style="display: none;" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit"> <i
                class="layui-icon">&#xe642;</i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                class="layui-icon">&#xe640;</i>删除</a>
    </div>
</script>
<script>
    layui.use(['table', 'form', 'tableSelect','laydate'],  function(){
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;
        tableSelect = layui.tableSelect;

        laydate.render({
            elem:'#businessTime'
        })
        //查询
        table.render({
            id: 'MyTable',
            elem: '#MyTable',
            url:'CashAccruedSelect', //数据接口
            height: 'full-55'
            , minLength: 80,
            page: true, //开启分页
            toolbar: '#fundToolBar',
            limits:[2,4,6,8],
            cols: [[ //表头
                {type: 'checkbox', fixed: 'left'},
                {field: 'cashAccruedId', title: '现金应收应付ID',}
                ,{field: 'fundId', title: '基金ID'}
                ,{field: 'businessTime', title: '业务日期',}
                ,{field: 'cashId', title: '现金账户',}
                ,{field: 'accountName', title: '现金账户名称',}

                ,{field: 'businessType', title: '业务类型' ,templet: function (item) {
                        if (item.businessType=='1'){
                            return '管理费';
                        }else if (item.businessType=='2'){
                            return '托管费'
                        }else if (item.businessType=='3'){
                            return '存款利息'
                        }else if (item.businessType=='3'){
                            return '申购赎回'
                        }
                    }}
                ,{field: 'fundFlow', title: '资金流向' , templet: function (item) {
                        if (item.fundFlow=='1'){
                            return '流入';
                        }else if (item.fundFlow=='-1'){
                            return '流出'
                        }
                    }}
                ,{field: 'money', title: '总金额'}
                ,{fixed: 'right', align:'center', toolbar: '#barDemo',width:200}//编辑删除的按钮
            ]]
        });
        laydate.render({
            elem:'#timeQ'
        });
        table.on('toolbar(MyTable)', function (obj) {
                if (obj.event == 'search'){
                 var time = $('#timeQ').val();
                    var businessTypeID = $('#businessTypeID').val();
                    alert(businessTypeID);
                 table.reload('MyTable', {
                     method: 'post',
                     where: {
                         'businessTime': time,
                         'businessType': businessTypeID
                     },
                     page: {
                         curr : 1
                     },
                    });
                    laydate.render({
                        elem:'#timeQ'
                    });
                    $('#timeQ').val(time);
                    $('#businessTypeID').val(businessTypeID);
            }else if (obj.event == 'insert'){
                    alert("123")
                    layer.open({
                        type: 1,
                        title: '添加基金信息',
                        closeBtn: 1,
                        move:false,
                        area: ['800px', '400px'],
                        content:$("#addContent")

                    });
                }
        });

        //给增加的form绑定提交事件
        form.on('submit(addsubmit)',function () {
            alert("新增表单提交");
            //发送ajax请求到 服务器，
            //得到表单的所有数据
            var formData= form.val("addform");
            // alert('formData=' + formData);
            $.post(
                "insertCashAccrued",
                formData,
                function(msg) {
                    //重新刷新表格
                    //给予提示信息，增加成功
                    // alert(msg);
                    if(msg==0){
                        alert('增加失败');
                    }else {
                        alert('增加成功')
                    }
                });
        });

        //新增托管人下拉表格
        tableSelect.render({
            elem: '#cashId',
            checkedKey: 'cashId',
            table: {
                url: 'selectCash',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        , {field: 'bankId', title: '银行卡号', edit: 'text', align:'center'}
                        , {field: 'accountName', title: '账户名称', edit: 'text', align:'center'}
                        , {field: 'bankName', title: '银行名称', edit: 'text', align:'center'}
                    ]]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.cashId)
                    $("#hidden").val(item.cashId)
                });
                elem.val(NEWJSON.join(","))
            }
        });


        tableSelect.render({
            elem: '#cashIdQ',
            checkedKey: 'cashId',
            table: {
                url: 'selectCash',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        , {field: 'bankId', title: '银行卡号', edit: 'text', align:'center'}
                        , {field: 'accountName', title: '账户名称', edit: 'text', align:'center'}
                        , {field: 'bankName', title: '银行名称', edit: 'text', align:'center'}
                    ]]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.cashId)
                    $("#hiddenQ").val(item.cashId)
                });
                elem.val(NEWJSON.join(","))
            }
        });

        //给最右边的列 添加事件
        table.on('tool(MyTable)',function (obj) {
            switch (obj.event) {
                case "edit":
                    //得到选中行的数据
                    var data=obj.data;
                    //JSON.stringify(data)  拼接成JSON格式的字符串
                    var bookObj=$.parseJSON(JSON.stringify(data));
                    //弹出一个修改的窗口
                    form.val("editform",bookObj);
                    layer.open({
                        type:1, //iframe 内嵌窗口
                        title: '修改基金设置信息',
                        area: ['800px', '400px'],
                        content: $("#editContent")
                    });
                    break;
                case "del":
                    // alert("这是删除的操作");
                    alert("选中的行：" + obj.data.cashAccruedId);
                    layer.confirm('您确定要删除吗', function (index) {
                        console.log(obj.data.cashAccruedId)
                        $.getJSON("deleteCashAccrued"
                            , {cashAccruedId: obj.data.cashAccruedId}
                            , function (msg) {
                                if (msg == 1) {
                                    layer.close(index)
                                    table.reload('MyTable');
                                }
                            })
                    })
                    break;
            }
        });

        //给修改的form绑定提交事件
        form.on('submit(editform)',function () {
            //发送ajax请求到 服务器，
            //得到表单的所有数据
            var formData= form.val("editform");
            // alert('formData=' + formData);
            $.post(
                "updateCashAccrued",
                formData,
                function(msg) {
                    //重新刷新表格
                    //给予提示信息，修改成功
                    // alert(msg);
                    if(msg==0){
                        alert('修改失败');
                    }else {
                        alert('修改成功');
                    }
                });

        });
    });
</script>
<!--表格-->
<table id="MyTable" lay-filter="MyTable"></table>


<!--增加的div内容-->
<div id="addContent"
     style="display: none; height: 100%; height: 100%; text-align: center;">
    <form id="addform" lay-filter="addform"
          class="layui-form layui-form-pane"
          style="margin: 30px auto; display: inline-block;">
        <div class="layui-form-item" style="atext-align: center;">
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 35px;">业务日期</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="businessTime" id="businessTime"
                       autocomplete="off" placeholder="请输入业务日期" class="layui-input">
            </div>
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 50px;">现金账户</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="cashId" id="cashId"
                       autocomplete="off" placeholder="请输入现金账户" class="layui-input">
                <input type="hidden" name="fundName" id="hidden">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 35px">业务类型</label>
            <div class="layui-input-inline">
                <select name="businessType" >
                    <option placeholder="请选择"></option>
                    <option value="1" >管理费</option>
                    <option value="2">托管费</option>
                    <option value="3">存款利息</option>
                    <option value="4">申购赎回</option>
                </select>
            </div>
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 50px;">资金流向</label>
            <div class="layui-input-inline">
                <select name="fundFlow" >
                    <option placeholder="请选择"></option>
                    <option value="1" >流入</option>
                    <option value="-1">流出</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 35px">总金额</label>
            <div class="layui-input-inline">
                <div class="layui-input-inline">
                    <input type="text" lay-verify="required" name="money" id="money"
                           autocomplete="off" placeholder="请输入总金额" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="position: absolute;left: 28%; bottom: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="addsubmit"><i class="layui-icon">&#x1005;</i>添加</button>
                <button type="reset" class="layui-btn layui-btn-primary"> <i class="layui-icon">&#x1006;</i>取消</button>
            </div>
        </div>
    </form>
</div>
<!--修改的div内容-->
<div id="editContent"  style="display: none; height: 100%; height: 100%; text-align: center;">
    <form id="editform" lay-filter="editform"
          class="layui-form layui-form-pane"
          style="margin: 30px auto; display: inline-block;">

        <div class="layui-form-item" style="atext-align: center;">
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 35px;">现金应收应付ID </label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="cashAccruedId" id="cashAccruedId"
                       autocomplete="off" placeholder="请输入业务日期" class="layui-input">
            </div>
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 50px;">基金ID</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="fundId" id="fundId"
                       autocomplete="off" placeholder="请输入现金账户" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" style="atext-align: center;">
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 35px;">业务日期</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="businessTime" id="businessTimeQ"
                       autocomplete="off" placeholder="请输入业务日期" class="layui-input">
            </div>
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 50px;">现金账户</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="cashId" id="cashIdQ"
                       autocomplete="off" placeholder="请输入现金账户" class="layui-input">
                <input type="hidden" name="fundName" id="hiddenQ">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 35px">业务类型</label>
            <div class="layui-input-inline">
                <select name="businessType" >
                    <option placeholder="请选择"></option>
                    <option value="1" >管理费</option>
                    <option value="2">托管费</option>
                    <option value="3">存款利息</option>
                    <option value="4">申购赎回</option>
                </select>
            </div>
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 50px;">资金流向</label>
            <div class="layui-input-inline">
                <select name="fundFlow" >
                    <option placeholder="请选择"></option>
                    <option value="1" >流入</option>
                    <option value="-1">流出</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 35px">总金额</label>
            <div class="layui-input-inline">
                <div class="layui-input-inline">
                    <input type="text" lay-verify="required" name="money"
                           autocomplete="off" placeholder="请输入总金额" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="position: absolute;left: 28%; bottom: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="addsubmit"><i class="layui-icon">&#x1005;</i>添加</button>
                <button type="reset" class="layui-btn layui-btn-primary"> <i class="layui-icon">&#x1006;</i>取消</button>
            </div>
        </div>
    </form>
</div>

</body>
</html>